# -*-coding:utf-8 -*-

"""
# File       : TokenCustomBackend.py
# Time       ：2022/8/20 下午5:31
# Author     ：puppet
# version    ：python 3.8.1
# Description：
"""

# views中重写authenticate认证
from django.contrib.auth import get_user_model
from django.contrib.auth.backends import ModelBackend
User = get_user_model()


# Create your views here.
class CustomBackend(ModelBackend):
    def authenticate(self, username=None, password=None, **kwargs):
        try:
            user = User.objects.get(username=username)
            if user.check_password(password):
                return user
        except Exception as e:
            return None

